<template>
	<view>
		<headerTar title="扫码" :isBack="false">
		</headerTar>
		<view class="noData">
			设备不存在或不在线~
		</view>
	</view>
</template>

<script>
	import {
		getDeviceByDeviceNoAPi
	} from '@/api/pay.js'
	import headerTar from '@/components/headerTar/header'
	export default {
		components: {
			headerTar
		},
		data() {
			return {
				hasOnShow: false,
				show: false
			}
		},
		onLoad() {},
		onShow() {
			console.log(this.hasOnShow);
			if (this.hasOnShow) {
				return this.hasOnShow = false
			}
			this.hasOnShow = true
			this.scanCode()
		},
		methods: {
			// 点击扫一扫按钮
			scanCode() {
				uni.scanCode({
					success: (res) => {
						console.log('扫码成功', res)
						//"https://dev.5gtxxny.com/ss11/2"
						let urlList = res.result.split('/')
						//扫码跳转
						getDeviceByDeviceNoAPi({
							deviceNo: urlList[urlList
								.length - 1]
						}).then(res => {
							uni.navigateTo({
								url: '/pages/scanCodeDetail/scanCodeDetail?deviceId=' +
									JSON
									.stringify(res.data)
							})
						})
					},
					fail: (err) => {
						console.log('扫码失败', err)
						uni.switchTab({
							url: '/pages/index/index'
						})
					},
					complete: () => {
						console.log('扫码结束')
					}
				})
			},
			handelUrl(val) {
				//https://dev.5gtxxny.com/${设备类型}/${设备号}

			}
		}
	}
</script>

<style scoped>
	.noData {
		margin-top: 60rpx;
		text-align: center;
		color: #a8a8a8;
	}
</style>